/**
 *	VisualGroup JavaScript prototype Classes, version 0.1
 *  (c) 2008 Bill Vison <vison_ruan@126.com>
 *
 *
/*--------------------------------------------------------------------------*/
Vsg.FlashHttpRequest = {
	
	/**
	 * run the debug mode
	 */
	flash_debug:function($obj) {
		Ext.log("debug outer : " + $obj);
	},
	
	flash_reponseHandle:function ($obj) {
		// --- handle response ---
		var $response = {
			tld:0,
			status:200,
			starusText:"OK",
			responseText:$obj.data,
			argument:this.opt
		}
        Ext.callback(this.opt.success, this.opt.scope, [$response, this.opt]);
        Ext.callback(this.opt.callback, this.opt.scope, [this.opt, true, $response]);

	},
	
	flash_failureHandle:function ($obj) {
		Ext.log("fail handle : " + $obj);
	},
	
	flash_httpStatus:function ($obj) {
		Ext.log("$ok : " + $obj);
	},	
	
	request:function($opt) {

		if ($opt.url == null) {
			throw new Vsg.FlashHttpRequest.Exception("没有设发送请求的URL!" , null , Vsg.FlashHttpRequest.Exception.ParameterNoNullException );			
		}
		
		// --- defined request handle ---
		if (!$opt.scope) {
			$opt.scope = this;
		}
		
		this.opt = $opt;
		
		
		// --- generate the new option ---
		var $options = {
			url:$opt.url
		}
		
		if ($opt.params != null) {
			$options.params = $opt.params;
		}
		
		// --- get the flash common
		var $el = Ext.get("flashProxyConnection");
		var $flashProxy = $el.dom;
		try {
			try {
				var $profile = Ext.state.Manager.get(Vsg.PROFILE);
				var $prolicyfile = "http://" + $profile.server.host + ":" + $profile.server.port + $profile.server.flashProlicyfile;
				$flashProxy.initProlicyFile($prolicyfile);
			} catch (e) {
				throw "加载Flash跨域策略文件出错! " + e;
			}
			
			$flashProxy.sendAndLoad($options);			
		} catch (ex) {
			Ext.log( ex );
		}

	}
};

Vsg.FlashHttpRequest.Exception = Ext.extend(Exception.CommonException,{
	name:"Vsg.FlashHttpRequest.Exception",
	constructor:function($message , $name ,$value) {
		Vsg.FlashHttpRequest.Exception.superclass.constructor.apply(this, arguments);
	}
});

Vsg.FlashHttpRequest.Exception.ParameterNoNullException = 1;


/** check interface implement */
Ext.onReady(function() {

	var $contextUrl = getRootScriptContent();
	var $movie = $contextUrl+"/depenthird/flash/FlashHttpRequest_v2.swf";
	
	// --- create tag ---
	var $tag = {
		id:"flashProxyConnection",
		tag:'object',
		classid:"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
		codebase:"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0",
		name:"flashProxyConnection",
		width:"1",
		height:"1",
		align:"middle",
		children:[
			{tag:"param" , name:"allowScriptAccess" , value:"always" },
			{tag:"param" , name:"allowFullScreen" , value:"false" },
			{tag:"param" , name:"movie" , value:$movie },
			{tag:"param" , name:"quality" , value:"high" },
			{tag:"param" , name:"bgcolor" , value:"#ffffff" },
			{
				tag:"embed" ,
				name:"flashProxyConnection", 
				src:$movie , 
				bgcolor:"#ffffff",
				allowScriptAccess:"always",
				allowFullScreen:"false",
				type:"application/x-shockwave-flash",
				pluginspage:"http://www.macromedia.com/go/getflashplayer",
				width:"1",
				height:"1",
				align:"middle",
				quality:"high"
			}
		]
	};
	if ( Ext.get("flashProxyConnection") == null) {
		Ext.DomHelper.append( Ext.getBody() ,  $tag , false);
	
	}
});
